package cn.iocoder.yudao.module.blog.dal.mysql.poster;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.blog.dal.dataobject.poster.PosterDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.blog.controller.admin.poster.vo.*;

/**
 * 海报 Mapper
 *
 * @author 曹建伟
 */
@Mapper
public interface PosterMapper extends BaseMapperX<PosterDO> {

    default PageResult<PosterDO> selectPage(PosterPageReqVO reqVO) {
        if(reqVO.getNowTime() != null){
            return selectPage(reqVO, new LambdaQueryWrapperX<PosterDO>()
                    .le(PosterDO::getRecommendStartTime, reqVO.getNowTime())
                    .ge(PosterDO::getRecommendEndTime, reqVO.getNowTime())
                    .orderByDesc(PosterDO::getId));
        }else {
            return selectPage(reqVO, new LambdaQueryWrapperX<PosterDO>()
                    .betweenIfPresent(PosterDO::getCreateTime, reqVO.getCreateTime())
                    .eqIfPresent(PosterDO::getTypeId, reqVO.getTypeId())
                    .orderByDesc(PosterDO::getId));
        }
    }

    default List<PosterDO> selectList(PosterExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PosterDO>()
                .gtIfPresent(PosterDO::getRecommendStartTime, reqVO.getNowTime())
                .ltIfPresent(PosterDO::getRecommendEndTime, reqVO.getNowTime())
                .betweenIfPresent(PosterDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(PosterDO::getTypeId, reqVO.getTypeId())
                .orderByDesc(PosterDO::getId));
    }

}
